import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';



import '../../AppConfig/Config.dart';
import '../../AppConfig/RouteAct.dart';
import '../../http/NoLoadingGetApi.dart';
import '../../l10n/messages.dart';
import 'AddbankCard.dart';
import 'BankCardDetails.dart';

class BankCardList extends StatefulWidget {
  const BankCardList({super.key});

  @override
  State<BankCardList> createState() => _BankCardListState();
}

class _BankCardListState extends State<BankCardList> {
  List cardName=["中国银行","中国建设银行"];
  List dataList=[];
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getBankList();
  }
  void getBankList(){
    NoLoadinggetApiManager.getData(
      context,
      "api/pay/pay/driver/bankcard/page",
      {'current':1,"size":20},
          (responseData)  {
        setState(() {
          dataList=responseData['data']['records'];

        });
      },
    );
  }
  @override
  Widget build(BuildContext context) {
    var messages = AppLocalizations.of(context)!;
    final screenSize = MediaQuery.of(context).size;
    return Scaffold(
      backgroundColor: MyColors.backgreyColor,
      appBar: AppBar(
        leading: IconButton(
          icon: Icon(Icons.arrow_back_ios, color: Colors.black),
          onPressed: () => Navigator.of(context).pop(),
        ),
        backgroundColor: Colors.white,
        centerTitle: true,
        title: Text(messages['银行卡'],style: TextStyle(color: Colors.black,fontWeight: FontWeight.w300,fontSize: 16.sp),),
      ),
      body: ListView(
        children: [
          Container(
            height: dataList.length*110.h,
            child:    ListView.builder(
                physics: NeverScrollableScrollPhysics(),
                shrinkWrap:false,
                itemCount: dataList.length,
                itemBuilder: (BuildContext context, int index) {
                  return GestureDetector(
                    child:  Container(
                      margin: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h),
                      padding: EdgeInsets.only(top:14.h,bottom: 10.h ,left: 13.w),
                      decoration: BoxDecoration(
                        color:Colors.white,
                        borderRadius: BorderRadius.all(Radius.circular(10)),
                      ),
                      child: Column(
                        children: [
                          Row(
                            children: [
                              Image.asset("lib/Images/PersonCenter/银行卡icon.png",width: 20.w,height: 20.h,),
                              SizedBox(width: 4.w,),
                              Text(dataList[index]['bankName'],style: TextStyle(color: Colors.black,fontSize: 16.sp),),
                            ],
                          ),
                          Row(
                            children: [
                              SizedBox(width: 30.w,),
                              Text(dataList[index]['type'],style: TextStyle(color: MyColors.textColor,fontSize: 14.sp),),
                            ],
                          ),
                          Text("····"+" "+"····"+" "+"····"+" "+dataList[index]['bankCard'].substring(dataList[index]['bankCard'].length - 4),style: TextStyle(color: Colors.black,fontSize: 26.sp,fontWeight: FontWeight.w600),),
                        ],
                      ),
                    ),
                    onTap: ()async{

                      final result=await Navigator.push( context, FadeRoute(page:BankCardDetails(dataMap: dataList[index],)));
                      if(result!=null){
                        getBankList();
                      }
                    },
                  );
                }
            ),
          ),
          GestureDetector(
            child:  Container(
              margin: EdgeInsets.only(left: 10.w,right: 10.w),
              padding: EdgeInsets.only(top: 10.h,bottom: 10.h,left: 10.w),
              decoration: BoxDecoration(
                color:Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(10)),
              ),
              child: Row(
                children: [
                  Icon(Icons.add_circle_outline,color: MyColors.textColor,),
                  SizedBox(width: 4.w,),
                  Text("添加银行卡",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                ],
              ),
            ),
            onTap: ()async{

              final result=await Navigator.push( context, FadeRoute(page:AddBankCard()));
              if(result!=null){
                getBankList();
              }
            },
          ),

        ],

      ),
    );
  }
}
